//
//  ViewController.m
//  MJGHTMLReaderDemo
//
//  Created by Mei Jigao on 15/4/21.
//  Copyright (c) 2015年 MeiJigao. All rights reserved.
//

#import "ViewController.h"
#import "MJGHTMLReader.h"

@interface ViewController () <MJGHTMLReaderUrlDocumentDelegate> {
    
    IBOutlet UITextField *urlField;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)paraseHTML:(id)sender {
    
    NSString *urlStr = [urlField.text length] > 0 ? urlField.text : @"http://www.baidu.com";
    NSURL *requestUrl = [NSURL URLWithString:urlStr];
    
    MJGHTMLReader *htmlReader = [[MJGHTMLReader alloc] init];
    [htmlReader setDocumentElementWithUrl:requestUrl delegate:self];
}

#pragma mark - MJGHTMLReaderUrlDocumentDelegate
- (void)htmlFieldRead:(MJGHTMLReader *)htmlReader didFinisheLoading:(NSError *)loadError {
    
    if (!loadError) {
        
        [htmlReader logOutHTMLElement];
    }
}

#pragma mark - end

@end
